package com.starinside.wp;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2 {

    @Bean
    public Docket createStarinsideRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("家长端接口")
                .apiInfo(apiInfo("智能芯"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.starinside.wp.controller.api"))
                .paths(PathSelectors.any())
                .build();
    }

//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//                .title("家长端 API 文档")
//                .description("微信接口 API 会使用 session 绑定用户，以适应微信的鉴权环境。")
//                .termsOfServiceUrl("http://starinside.cn/")
//                .contact(new Contact("Ron","http://sigarron.dev", "luoying@starinside.cn"))
//                .version("1.0")
//                .build();
//    }
    private ApiInfo apiInfo(String name) {
        return new ApiInfoBuilder()
                .title("家长端 API 文档 - " + name) //大标题
                .description("")
                .termsOfServiceUrl("http://dotflat.cn/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createDailyRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("宝宝一日")
                .apiInfo(apiInfo("宝宝一日"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.matt.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApi() {
        com.google.common.base.Predicate<RequestHandler> selector = RequestHandlerSelectors.basePackage("com.dotflat");
        Docket ret = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("通用Rest风格API"))
                .select()
                .apis(selector)
                .paths(PathSelectors.any())
                .build()
                .groupName("通用Rest风格API");
        return ret;
    }
//    private ApiInfo dailyApiInfo() {
//        return new ApiInfoBuilder()
//                .title("宝宝一日 API 文档")
//                .description("微信接口 API 会使用 session 绑定用户，以适应微信的鉴权环境。")
//                .termsOfServiceUrl("http://starinside.cn/")
//                .contact(new Contact("Ron","http://sigarron.dev", "luoying@starinside.cn"))
//                .version("1.0")
//                .build();
//    }
}